package com.itheima.user.controller;

import com.itheima.user.domain.po.User;
import com.itheima.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/users")
public class UserController {

    @Autowired
    private IUserService userService;


    @PostMapping("/login")
    public String login(String phone, String pwd){
       String jwt =  userService.login(phone,pwd);
       return jwt;
    }

    @PostMapping("/register")
    public String register(User user){
       String result = userService.insert(user);
        return result ;
    }

    @DeleteMapping("/remove")
    public String deleteById(Long id){
        String result = userService.deleteById(id);
        return result;
    }

    @PutMapping("/update")
    public String updateById(User user){
        String result = userService.updateById(user);
        return result;
    }

    @GetMapping("/get")
    public User getById(@RequestParam("id") Long id){
        User user = userService.getById(id);
        return user;
    }
}
